package com.scs.application.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.exception.BusinessException;
import com.scs.application.core.service.BaseServiceImpl;
import com.scs.application.modules.sys.entity.SerialRule;
import com.scs.application.modules.sys.mapper.SerialRuleMapper;
import com.scs.application.modules.sys.service.SerialOwnerService;
import com.scs.application.modules.sys.service.SerialRuleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 编号规则 服务实现类
 * </p>
 */
@Slf4j
@Service
public class SerialRuleServiceImpl extends BaseServiceImpl<SerialRuleMapper, SerialRule> implements SerialRuleService {

    @Autowired
    private SerialOwnerService serialOwnerService;

    @Override
    public List<String> batchGenerateCode(SerialRule serialRule, String target, int count) {
        return serialOwnerService.batchGenerateCode(serialRule, target, count);
    }

    @Override
    public SerialRule getSerialRule(String ruleCode) {
        SerialRule serialRule = this.getOne(Wrappers.<SerialRule>query().eq("code", ruleCode).last("limit 1"));
        if (serialRule == null) {
            throw new BusinessException("编号规则[" + ruleCode + "]未找到，请确认是否配置");
        }
        return serialRule;
    }

    public Boolean isSupport(Boolean flagProject) {
        return flagProject;
    }
}
